package com.qaml.mes.device.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qaml.mes.device.dao.CheckUpkeepItemDO;
import com.qaml.mes.device.dao.mapper.CheckUpkeepItemMapper;
import com.qaml.mes.device.enums.DeletedEnum;
import com.qaml.mes.device.repository.CheckUpkeepItemRepository;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
 * @ClassName CheckUpkeepItemRepositoryImpl
 * @Description TODO
 * @Author leikai
 * @Date 2024/2/27 0027 9:49
 * @Version 1.0
 */
@Repository
public class CheckUpkeepItemRepositoryImpl implements CheckUpkeepItemRepository {

    @Resource
    private CheckUpkeepItemMapper checkUpkeepItemMapper;

    /**
     * 根据checkUpkeepId删除
     *
     * @param checkUpkeepId
     */
    @Override
    public void deleteByCheckUpkeepId(String checkUpkeepId) {
        LambdaQueryWrapper<CheckUpkeepItemDO> deleteQueryWrapper = new LambdaQueryWrapper<>();
        deleteQueryWrapper.eq(CheckUpkeepItemDO::getCheckUpkeepId, checkUpkeepId);
        checkUpkeepItemMapper.delete(deleteQueryWrapper);
    }

    /**
     * 批量保存在数据库中
     *
     * @param checkUpkeepItemDOS
     */
    @Override
    public void saveBatch(List<CheckUpkeepItemDO> checkUpkeepItemDOS) {
        checkUpkeepItemMapper.saveBatch(checkUpkeepItemDOS);
    }

    /**
     * 根据checkUpkeepId查询
     *
     * @param checkUpkeepId
     * @return
     */
    @Override
    public List<CheckUpkeepItemDO> getByCheckUpkeepId(String checkUpkeepId) {
        LambdaQueryWrapper<CheckUpkeepItemDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CheckUpkeepItemDO::getIsDeleted, 0);
        queryWrapper.eq(CheckUpkeepItemDO::getCheckUpkeepId, checkUpkeepId);
        List<CheckUpkeepItemDO> checkUpkeepItemDOS = checkUpkeepItemMapper.selectList(queryWrapper);

        if (checkUpkeepItemDOS == null || checkUpkeepItemDOS.isEmpty()) {
            return Collections.emptyList();
        }
        return checkUpkeepItemDOS;
    }

    /**
     * 批量修改检保条目
     *
     * @param ids
     */
    @Override
    public void updateCheckUpItemByIds(List<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        checkUpkeepItemMapper.updateCheckUpItemByIds(ids);
    }

    @Override
    public void updateByCheckUpKeepId(CheckUpkeepItemDO checkUpkeepItemDO) {
        LambdaQueryWrapper<CheckUpkeepItemDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CheckUpkeepItemDO::getCheckUpkeepId, checkUpkeepItemDO.getCheckUpkeepId());
        checkUpkeepItemMapper.update(checkUpkeepItemDO, queryWrapper);
    }

}